home *** CD-ROM | disk | FTP | other *** search
- #include "REALplugin.h"
- #ifndef powerc
- #include <A4Stuff.h>
- #include <SetupA4.h>
- #endif
- #include "rb_plugin.h"
-
-
- static void *(*gResolver)(const char *entryName);
-
- #ifdef powerc
- static void *(*gResolverPPC)(const char *entryName);
- #endif
-
- static Ptr *gA4Stack;
-
- #ifdef powerc
- int __procinfo = kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4));
- #endif
-
- #ifdef powerc
- //#define CallResolver(a) CallUniversalProc((RoutineDescriptor *) gResolver, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)), a)
- //#define Caller(func, upp) CallUniversalProc((RoutineDescriptor *) func, upp,
- #define CallResolver(a) gResolverPPC(a)
- #define Caller(func, upp) func(
- #else
- #define CallResolver(a) gResolver(a)
- #define Caller(func, upp) func(
- #endif
-
- /*
- void GraphicsDrawLine(Ptr graphicsObject, int x1, int y1, int x2, int y2)
- {
- static void (*pDrawLine)(Ptr graphicsObject, int x1, int y1, int x2, int y2);
- if (!pDrawLine)
- pDrawLine = (void (*)(Ptr graphicsObject, int x1, int y1, int x2, int y2)) CallResolver("RuntimeGraphicsDrawLine");
- pDrawLine(graphicsObject, x1, y1, x2, y2);
- }
- */
- /*
- void REALRegisterClass(REALobjectDefinition *defn)
- {
- static void (*pRuntimeRegisterClass)(REALobjectDefinition *defn);
- if (!pRuntimeRegisterClass)
- pRuntimeRegisterClass = (void (*)(REALobjectDefinition *)) CallResolver("PluginRegisterClass");
- Caller(pRuntimeRegisterClass, kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) defn);
- }
- */
- void REALRegisterMethod(REALmethodDefinition *defn)
- {
- static void (*pRuntimeRegisterMethod)(REALmethodDefinition *defn);
- if (!pRuntimeRegisterMethod)
- pRuntimeRegisterMethod = (void (*)(REALmethodDefinition *)) CallResolver("PluginRegisterMethod");
- Caller(pRuntimeRegisterMethod, kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) defn);
- }
-
- void REALRegisterControl(REALcontrol *defn)
- {
- static void (*pRuntimeRegisterControl)(REALcontrol *defn);
- if (!pRuntimeRegisterControl)
- pRuntimeRegisterControl = (void (*)(REALcontrol *)) CallResolver("PluginRegisterControl");
- Caller(pRuntimeRegisterControl, kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) defn);
- }
-
- const char *REALCString(REALstring str)
- {
- static const char *(*pStringGetCString)(REALstring str);
- if (!pStringGetCString)
- pStringGetCString = (const char *(*)(REALstring)) CallResolver("StringGetCString");
- return (const char *) Caller(pStringGetCString, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) str);
- }
-
- const unsigned char *REALPString(REALstring str)
- {
- static const unsigned char *(*pStringGetPString)(REALstring str);
- if (!pStringGetPString)
- pStringGetPString = (const unsigned char *(*)(REALstring)) CallResolver("StringGetPString");
- return (const unsigned char *) Caller(pStringGetPString, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) str);
- }
-
- REALstring REALBuildString(const char *contents, int length)
- {
- static REALstring (*pREALBuildString)(const char *contents, int length);
- if (!pREALBuildString)
- pREALBuildString = (REALstring (*)(const char *, int)) CallResolver("REALBuildString");
- return pREALBuildString(contents, length);
- }
-
- REALpicture REALBuildPictureFromPicHandle(PicHandle pic, Boolean bPassOwnership)
- {
- static REALpicture (*pREALBuildPictureFromPicHandle)(PicHandle, Boolean);
- if (!pREALBuildPictureFromPicHandle)
- pREALBuildPictureFromPicHandle = (REALpicture (*)(PicHandle, Boolean)) CallResolver("REALBuildPictureFromPicHandle");
- return pREALBuildPictureFromPicHandle(pic, bPassOwnership);
- }
-
- REALpicture REALBuildPictureFromGWorld(GWorldPtr world, Boolean bPassOwnership)
- {
- static REALpicture (*pREALBuildPictureFromGWorld)(GWorldPtr, Boolean);
- if (!pREALBuildPictureFromGWorld)
- pREALBuildPictureFromGWorld = (REALpicture (*)(GWorldPtr, Boolean)) CallResolver("REALBuildPictureFromGWorld");
- return pREALBuildPictureFromGWorld(world, bPassOwnership);
- }
-
- void *REALGetEventInstance(REALcontrolInstance instance, REALevent *event)
- {
- static void *(*pGetEventInstance)(REALcontrolInstance instance, int builtHook);
- #ifdef powerc
- if (!pGetEventInstance)
- pGetEventInstance = (void *(*)(REALcontrolInstance,int)) CallResolver("GetEventInstancePPC");
- return (void *) Caller(pGetEventInstance, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(4))) instance, event->forSystemUse);
- #else
- if (!pGetEventInstance)
- pGetEventInstance = (void *(*)(REALcontrolInstance,int)) CallResolver("GetEventInstance");
- return (void *) Caller(pGetEventInstance, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(4))) instance, event->forSystemUse);
- #endif
- }
-
- void *REALGetControlData(REALcontrolInstance instance, REALcontrol *defn)
- {
- return ((Ptr) instance) + defn->forSystemUse;
- }
-
- void REALGetControlBounds(REALcontrolInstance instance, Rect *rBounds)
- {
- static void (*pGetControlBounds)(REALcontrolInstance, Rect *);
- if (!pGetControlBounds)
- pGetControlBounds = (void (*)(REALcontrolInstance, Rect *)) CallResolver("GetControlBounds");
- Caller(pGetControlBounds, kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(4))) instance, rBounds);
- }
-
- REALfolderItem REALFolderItemFromFSSpec(const FSSpec *spec)
- {
- static REALfolderItem (*pFolderItemFromFSSpec)(const FSSpec *);
- if (!pFolderItemFromFSSpec)
- pFolderItemFromFSSpec = (REALfolderItem (*)(const FSSpec *)) CallResolver("FolderItemFromFSSpec");
- return pFolderItemFromFSSpec(spec);
- }
-
- Boolean REALFSSpecFromFolderItem(FSSpec *spec, REALfolderItem item)
- {
- static Boolean (*pREALFSSpecFromFolderItem)(FSSpec *, REALfolderItem);
- if (!pREALFSSpecFromFolderItem)
- pREALFSSpecFromFolderItem = (Boolean (*)(FSSpec *, REALfolderItem)) CallResolver("REALFSSpecFromFolderItem");
- return pREALFSSpecFromFolderItem(spec, item);
- }
-
- void REALSelectGraphics(REALgraphics context)
- {
- static void (*pSelectGraphics)(REALgraphics);
- if (!pSelectGraphics)
- pSelectGraphics = (void (*)(REALgraphics)) CallResolver("SelectGraphics");
- pSelectGraphics(context);
- }
-
- REALsound REALBuildSoundFromHandle(Handle sound, Boolean bPassOwnership)
- {
- static REALsound (*pREALBuildSoundFromHandle)(Handle, Boolean);
- if (!pREALBuildSoundFromHandle)
- pREALBuildSoundFromHandle = (REALsound (*)(Handle, Boolean)) CallResolver("REALBuildSoundFromHandle");
- return pREALBuildSoundFromHandle(sound, bPassOwnership);
- }
-
- REALappleEvent REALBuildAppleEvent(const AppleEvent *event, Boolean bPassOwnership)
- {
- static REALappleEvent (*pREALBuildAppleEvent)(const AppleEvent *);
- if (!pREALBuildAppleEvent)
- pREALBuildAppleEvent = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAppleEvent");
- return pREALBuildAppleEvent(event);
- }
-
- REALappleEvent REALBuildAEDescList(const AppleEvent *event, Boolean bPassOwnership)
- {
- static REALappleEvent (*pREALBuildAEDescList)(const AppleEvent *);
- if (!pREALBuildAEDescList)
- pREALBuildAEDescList = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAEDescList");
- return pREALBuildAEDescList(event);
- }
-
- REALappleEvent REALBuildAEObjSpecifier(const AppleEvent *event, Boolean bPassOwnership)
- {
- static REALappleEvent (*pREALBuildAEObjSpecifier)(const AppleEvent *);
- if (!pREALBuildAEObjSpecifier)
- pREALBuildAEObjSpecifier = (REALappleEvent (*)(const AppleEvent *)) CallResolver("REALBuildAEObjSpecifier");
- return pREALBuildAEObjSpecifier(event);
- }
-
- AppleEvent *REALAccessAppleEvent(REALappleEvent event)
- {
- static AppleEvent *(*pREALAccessAppleEvent)(REALappleEvent);
- if (!pREALAccessAppleEvent)
- pREALAccessAppleEvent = (AppleEvent *(*)(REALappleEvent)) CallResolver("REALAccessAppleEvent");
- return pREALAccessAppleEvent(event);
- }
-
- AppleEvent *REALAccessAppleEventReply(REALappleEvent event)
- {
- static AppleEvent *(*pREALAccessAppleEventReply)(REALappleEvent);
- if (!pREALAccessAppleEventReply)
- pREALAccessAppleEventReply = (AppleEvent *(*)(REALappleEvent)) CallResolver("REALAccessAppleEventReply");
- return pREALAccessAppleEventReply(event);
- }
-
- WindowPtr REALGetWindowHandle(REALwindow window)
- {
- static WindowPtr (*pREALGetWindowHandle)(REALwindow);
- if (!pREALGetWindowHandle)
- pREALGetWindowHandle = (WindowPtr (*)(REALwindow)) CallResolver("REALGetWindowHandle");
- return pREALGetWindowHandle(window);
- }
-
- ControlHandle REALGetControlHandle(REALcontrolInstance control)
- {
- static ControlHandle (*pREALGetControlHandle)(REALcontrolInstance);
- if (!pREALGetControlHandle)
- pREALGetControlHandle = (ControlHandle (*)(REALcontrolInstance)) CallResolver("REALGetControlHandle");
- return pREALGetControlHandle(control);
- }
-
- MenuHandle REALGetPopupMenuHandle(REALpopupMenu popup)
- {
- static MenuHandle (*pREALGetPopupMenuHandle)(REALpopupMenu);
- if (!pREALGetPopupMenuHandle)
- pREALGetPopupMenuHandle = (MenuHandle (*)(REALpopupMenu)) CallResolver("REALGetPopupMenuHandle");
- return pREALGetPopupMenuHandle(popup);
- }
-
- void main(void *(*resolver)(const char *entryName))
- {
- short *glue;
- int i;
- void (*pRegisterPluginExports)(REALexport *table);
-
- #ifndef powerc
- EnterCodeResource();
- #endif
- gResolver = resolver;
-
- #ifndef powerc
- unsigned long unglue;
- unsigned long a4stack;
- unsigned long (*getA4stack)(void);
- long pluginA4;
- unsigned long originalCode;
- void *glueProc;
-
- getA4stack = (unsigned long(*)(void)) resolver("getA4stackReference");
-
- glue = (short *) NewPtr(pluginExportCode * 52);
- a4stack = getA4stack();
- pluginA4 = GetCurrentA4();
-
- for (i = 0; i < pluginExportCode; i++)
- {
- unglue = (unsigned long) (glue + 17);
- originalCode = (unsigned long) pluginExports[i].proc;
-
- glueProc = glue;
-
- *glue++ = 0x2079; // movea.l $, A0
- *glue++ = (short) (a4stack >> 16);
- *glue++ = (short) (a4stack & 0xffff);
- *glue++ = 0x210c; // move.l A4, -(A0)
- *glue++ = 0x211f; // move.l (A7)+, -(A0)
- *glue++ = 0x287c; // move.l #, A4
- *glue++ = (short) (pluginA4 >> 16);
- *glue++ = (short) (pluginA4 & 0xffff);
- *glue++ = 0x2f3c; // move.l #, -(A7)
- *glue++ = (short) (unglue >> 16);
- *glue++ = (short) (unglue & 0xffff);
- *glue++ = 0x23c8; // move.l A0, $
- *glue++ = (short) (a4stack >> 16);
- *glue++ = (short) (a4stack & 0xffff);
- *glue++ = 0x4ef9; // jmp $
- *glue++ = (short) (originalCode >> 16);
- *glue++ = (short) (originalCode & 0xffff);
-
- *glue++ = 0x2279; // movea.l $, A1
- *glue++ = (short) (a4stack >> 16);
- *glue++ = (short) (a4stack & 0xffff);
- *glue++ = 0x2f19; // move.l (A1)+,-(A7)
- *glue++ = 0x2859; // movea.l (A1)+, A4
- *glue++ = 0x23c9; // move.l A1, $
- *glue++ = (short) (a4stack >> 16);
- *glue++ = (short) (a4stack & 0xffff);
- *glue++ = 0x4e75; // rts
-
- pluginExports[i].proc = glueProc;
- }
- #else
- gResolverPPC = (void *(*)(const char *)) CallUniversalProc((RoutineDescriptor *) gResolver, kCStackBased | RESULT_SIZE(SIZE_CODE(4)) | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4)), "ResolverPPC");
-
- for (i = 0; i < pluginExportCode; i++)
- pluginExports[i].flags |= REALexportPPC;
- #endif
-
- pRegisterPluginExports = (void (*)(REALexport *)) CallResolver("RegisterPluginExports");
- Caller(pRegisterPluginExports, kCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(4))) pluginExports);
-
- PluginEntry();
-
- #ifndef powerc
- ExitCodeResource();
- #endif
- }
-